﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;

namespace IntegrationTest.App
{
    class Program
    {
        static void Main(string[] args)
        {
            System.Threading.ThreadPool.SetMinThreads(120, 120);
            System.Threading.ThreadPool.SetMaxThreads(240, 240);
            ServicePointManager.DefaultConnectionLimit = 1000;
            TestFactory testFactory = new TestFactory("testSection");
            testFactory.Run();
            DateTime dt = DateTime.Now;
            string path = AppDomain.CurrentDomain.BaseDirectory + @"report\";
            if (!System.IO.Directory.Exists(path))
                System.IO.Directory.CreateDirectory(path);
            string xmlfile = path + dt.ToString("yyyyMMddhhmmss") + ".xml";
            path += dt.ToString("yyyyMMddhhmmss") + ".log";

            while (true && !testFactory.Completed)
            {
                Console.Clear();
                foreach (IntegrationTest.TestCase item in testFactory.Cases)
                {
                    Console.WriteLine(item);
                }
                System.Threading.Thread.Sleep(990);
            }
            using (System.IO.StreamWriter writer = new System.IO.StreamWriter(path, false, Encoding.UTF8))
            {
                foreach (IntegrationTest.TestCase item in testFactory.Cases)
                {
                    writer.Write(item.ToString());
                }
            }

            using (System.Xml.XmlWriter xmlwriter = new System.Xml.XmlTextWriter(xmlfile, Encoding.UTF8))
            {
                xmlwriter.WriteStartElement("cases");
                foreach (IntegrationTest.TestCase item in testFactory.Cases)
                {
                    item.ToXML(xmlwriter);
                }
                xmlwriter.WriteEndElement();
            }

            Console.WriteLine("Test Completed log:" + path);

            System.Diagnostics.Process.Start(path);
            Console.WriteLine("enter any key to exit ...");
            Console.Read();

        }

    }
}
